package com.gitee.dupe.authority.entity;

import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.gitee.dolt.base.validation.LastGroup;
import com.gitee.dolt.core.base.entity.Entity;
import com.gitee.dolt.database.validator.ColumnUnique;
import com.gitee.dupe.authority.enumeration.RoleResourceScopeEnum;
import com.gitee.dupe.authority.service.IRoleService;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;

import javax.validation.GroupSequence;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author LYH
 * @since 2020-06-30
 */
@Data
@Accessors(chain = true)
@TableName("b_role")
@GroupSequence({Role.class, LastGroup.class})
@ColumnUnique(service = IRoleService.class, property = "ident", groups = LastGroup.class, message = "标识已存在")
public class Role extends Entity<Long> {

    /**
     * 标识
     */
    @ApiModelProperty(value = "标识")
    @Length(max = 255)
    @TableField(value = "ident", condition = SqlCondition.LIKE)
    private String ident;

    /**
     * 名称
     */
    @ApiModelProperty(value = "名称", required = true)
    @NotBlank
    @Length(max = 50)
    @TableField(value = "name", condition = SqlCondition.LIKE)
    private String name;

    /**
     * 是否可用
     */
    @ApiModelProperty(value = "是否启用", required = true)
    @NotNull
    @TableField(value = "enabled")
    private Boolean enabled;

    /**
     * 备注
     */
    @ApiModelProperty(value = "备注")
    @Length(max = 255)
    @TableField(value = "remark")
    private String remark;

    /**
     * 作用域
     */
    @ApiModelProperty(value = "作用域")
    @TableField(value = "scope")
    private RoleResourceScopeEnum scope;

    /**
     * 权限
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "资源", accessMode = ApiModelProperty.AccessMode.READ_ONLY)
    private List<Resource> resources;


}
